home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows4 / pcproj.zip / PERTTASK.CLS < prev    next >
Text File  |  1988-11-30  |  3KB  |  116 lines

  1. /* PERT Tasks are like regular tasks, but their time is
  2.    calculated based on the likely, best and worst cases.
  3.  
  4.    PERTTasks descend from Task and inherit all of
  5.    their methods and instance variables.
  6. */!!
  7.  
  8. inherit(Task, #PERTTask, #(likelyTime  /* for PERT calc time */ 
  9. bestTime    /* for PERT calc time */ 
  10. worstTime   /* for PERT calc time */
  11. variance    /* of calculated time */), 2, nil)!!
  12.  
  13. now(PERTTaskClass)!!
  14.  
  15. now(PERTTask)!!
  16.  
  17. /* Return the class name.  Uses resources for translation. */
  18. Def className(self)
  19. {
  20.   ^loadString(PW_PERTTASK);
  21. }!!
  22.  
  23. /* Return the appropriate dialog class to be used
  24.    by editInfo(). */
  25. Def  dialogClass(self)
  26. {
  27.   ^PERTDialog;
  28. }!!
  29.  
  30. /* Get the PERT worst time. */
  31. Def  getWorstTime(self)
  32.   ^worstTime;
  33. }!!
  34.  
  35. /* Get the PERT best time. */
  36. Def  getBestTime(self)
  37.   ^bestTime;
  38. }!!
  39.  
  40. /* Get the PERT likely time. */
  41. Def  getLikelyTime(self)
  42.   ^likelyTime;
  43. }!!
  44.  
  45. /* Set the values of an activity. 
  46.    Values is an array of name, desc,
  47.    userEarlyStart, userLateFinish, likelyTime
  48.    bestTime, worstTime, fixedCost, resources. */
  49. Def  setValues(self, values | oldUES, oldULF, oldTime, 
  50.                               oldLikely, oldBest, oldWorst)
  51. {
  52.   oldUES := userEarlyStart;
  53.   oldULF := userLateFinish;
  54.   oldTime := time;
  55.   oldLikely := likelyTime;
  56.   oldBest := bestTime;
  57.   oldWorst := worstTime;
  58.   
  59.   name := values[0];
  60.   desc := values[1];
  61.   userEarlyStart := values[2];
  62.   userLateFinish := values[3];
  63.   likelyTime := values[4];
  64.   bestTime := values[5];
  65.   worstTime := values[6];
  66.   
  67.   setFixedCost(self, values[7]);
  68.   checkResources(self, values[8]);
  69.  
  70.   if oldLikely <> likelyTime cor
  71.       oldBest <> bestTime cor
  72.       oldWorst <> worstTime
  73.      calcPERT(self);    /* recalc the PERT time */
  74.   endif;
  75.   
  76.   if network cand autoCalc(network) cand 
  77.      (oldUES <> userEarlyStart cor
  78.       oldULF <> userLateFinish cor
  79.       oldTime <> time)
  80.      recalc(self);     /* recalc the network */
  81.   endif;
  82. }!!
  83.  
  84. /* Get the PERT time, calculate it if invalidated. */
  85. Def  getTime(self)
  86.   if (time) 
  87.     ^time 
  88.   else 
  89.     ^calcPERT(self); 
  90.   endif;
  91. }!!
  92.  
  93. /* Init a new PERT Task. */
  94. Def  init(self)
  95. {
  96.   init(self:Task);      /* use ancestor init */
  97.   time := 0;            /* invalidate time */
  98.   bestTime := 0;
  99.   worstTime := 0;
  100.   likelyTime := 0;
  101.   variance := 0;
  102. } !!
  103.  
  104. /* For a PERT task, calculate the time and variance. 
  105.    Round it to an Int. */
  106. Def  calcPERT(self)
  107.   variance := ((worstTime - bestTime)/6.0)**2;
  108.   ^time := asInt(((bestTime + 4*likelyTime + worstTime) / 6.0) +.5);
  109. }!!
  110.  
  111.